<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="coinfaces">

        <title>互质勾股数的一般形式</title>

    <link rel="stylesheet" href="../../theme/css/style.css">
    <link rel="stylesheet" href="../../theme/css/pygments.css">



</head>

<body>
    <div class="content">
<h1>互质勾股数的一般形式</h1>    <p>
        under
            <a href="../../tags/number/">number</a>
    </p>
    <p>
        in <a href="../../categories/math/">math</a>
    </p>
    <p>Published: 2016-09-18</p>


    <div class="section" id="id2">
<h2>问题</h2>
<p>勾股数（西方叫毕达哥拉斯数）是可作为直角三角形三边长度的一组正整数，求证所有互质勾股数一定可以写成<span class="math">\(m^2 - n^2\)</span>、<span class="math">\(2mn\)</span>和<span class="math">\(m^2 + n^2\)</span>，其中<span class="math">\(m\)</span>和<span class="math">\(n\)</span>均为正整数， <span class="math">\(m &gt; n\)</span>。这个问题来自<a class="reference external" href="https://projecteuler.net/problem=9">Project Euler Problem 9</a>。</p>
</div>
<div class="section" id="id4">
<h2>证明1</h2>
<p>由<span class="math">\(a^2 + b^2 = c^2\)</span>和<span class="math">\(gcd(a, b, c) = 1\)</span>可知<span class="math">\(gcd(a, b) = gcd(b, c) = gcd(a, c) = 1\)</span>。</p>
<p>由奇偶性质判定<span class="math">\(a\)</span>、<span class="math">\(b\)</span>、<span class="math">\(c\)</span>中一定有偶数个奇数，由互质进一步得出必定2奇1偶。</p>
<div class="section" id="c">
<h3>反证c是奇数</h3>
<ul class="simple">
<li>假设<span class="math">\(c\)</span>是偶数，<span class="math">\(a\)</span>、<span class="math">\(b\)</span>是奇数，则<span class="math">\(a^2 = (c-b)(c+b)\)</span></li>
<li>因为<span class="math">\(b\)</span>、<span class="math">\(c\)</span>互质，且<span class="math">\(c-b\)</span>和<span class="math">\(c+b\)</span>都是奇数，所以<span class="math">\(gcd(c-b ,c+b) = gcd(\frac{(c+b) + (c-b)}{2}, \frac{(c+b)-(c-b)}{2}) = gcd(c, b) = 1\)</span></li>
<li>因为<span class="math">\(c-b\)</span> 和<span class="math">\(c+b\)</span>互质且乘积是完全平方数，所以这两个数都是完全平方数。</li>
<li>因为奇完全平方数之差一定能被4整除，所以<span class="math">\(b = \frac{(c+b) - (c-b)}{2}\)</span>能被2整除，与b是奇数的假设矛盾，因此c必然是奇数</li>
</ul>
</div>
<div class="section" id="abcmn">
<h3>用a、b和c表示m和n</h3>
<p>不失一般性，假设<span class="math">\(b\)</span>是偶数，则<span class="math">\(c+b\)</span>和<span class="math">\(c-b\)</span>都是奇完全平方数。</p>
<p>令<span class="math">\(m = \frac{\sqrt{c+b} + \sqrt{c-b}}{2}\)</span>，<span class="math">\(n = \frac{\sqrt{c+b} - \sqrt{c-b}}{2}\)</span>，则<span class="math">\(m\)</span>和<span class="math">\(n\)</span>都是整数，且<span class="math">\(m &gt; n\)</span>。</p>
<p>经验证<span class="math">\(m\)</span>、<span class="math">\(n\)</span>、<span class="math">\(a\)</span>、<span class="math">\(b\)</span>和<span class="math">\(c\)</span>满足<span class="math">\(c = m^2 + n^2\)</span>，<span class="math">\(b = 2mn\)</span>，<span class="math">\(a = m^2 - n^2\)</span>，证毕。</p>
</div>
</div>
<div class="section" id="id5">
<h2>证明2</h2>
<p>Project Euler用单位圆完成了一个巧妙的证明，其思路如下：</p>
<ul class="simple">
<li>勾股数<span class="math">\((2mn, m^2 - n^2, m^2 + n^2)\)</span>互质的充分必要条件是<span class="math">\(m\)</span>和<span class="math">\(n\)</span>互质，且一奇一偶。</li>
<li>若<span class="math">\(a^2 + b^2 = c^2\)</span>，令<span class="math">\(x = a/c\)</span>，<span class="math">\(y = b/c\)</span>，则<span class="math">\((x, y)\)</span>是单位圆上第一象限的一个点，且其坐标是有理数。</li>
<li>连接点<span class="math">\((x, y)\)</span>和<span class="math">\((0, -1)\)</span>得到一条斜率为<span class="math">\(s\)</span>的直线<span class="math">\((t, st - 1)\)</span>，可知<span class="math">\(s = \frac{c+b}{a} &gt; 1\)</span>，<span class="math">\(s\)</span>也是有理数。</li>
<li>用解析几何的方法求得<span class="math">\(s\)</span>表示的<span class="math">\((x, y)\)</span>点坐标<span class="math">\((\frac{2s}{s^2 + 1}, \frac{s^2 - 1}{s^2 + 1})\)</span>。</li>
<li>令<span class="math">\(s = \frac{m}{n}\)</span>，其中<span class="math">\(m\)</span>和<span class="math">\(n\)</span>是互质的整数，<span class="math">\(m &gt; n\)</span>，将其代入上述方程，得到<span class="math">\(x = \frac{2mn}{m^2+n^2}\)</span>，<span class="math">\(y = \frac{m^2 - n^2}{m^2 + n^2}\)</span>，则 <span class="math">\((2mn, m^2 - n^2, m^2 + n^2)\)</span>是勾股数，且三角形<span class="math">\((2mn, m^2 - n^2, m^2 + n^2)\)</span>和三角形<span class="math">\((a, b, c)\)</span>相似。</li>
<li>经过上述铺垫，如果<span class="math">\((a, b, c)\)</span>是互质的勾股数，则<span class="math">\((2mn, m^2 - n^2, m^2 + n^2)\)</span>一定是其整数倍。</li>
<li>如果<span class="math">\(m\)</span>和<span class="math">\(n\)</span>一奇一偶，则<span class="math">\((2mn, m^2 - n^2, m^2 + n^2)\)</span>互质，并且等同于<span class="math">\((a, b, c)\)</span>。</li>
<li>如果<span class="math">\(m\)</span>和<span class="math">\(n\)</span>都是奇数，令<span class="math">\(u = \frac{m+n}{2}\)</span>，<span class="math">\(v = \frac{m-n}{2}\)</span>，则<span class="math">\((u^2 - v^2) = mn\)</span>，<span class="math">\(uv = m^2 - n^2\)</span>，<span class="math">\(u^2 + v^2 = \frac{m^2 + n^2}{2}\)</span>，<span class="math">\(u\)</span>和<span class="math">\(v\)</span>一定是一奇一偶（否则<span class="math">\(m = u + v\)</span>，<span class="math">\(n = u - v\)</span>将都是偶数）且互质，勾股数<span class="math">\((u^2 - v^2, 2uv, u^2 + v^2)\)</span>即<span class="math">\((a, b, c)\)</span>。</li>
</ul>
<p>注意<span class="math">\(a\)</span>可以奇数也可以是偶数，而将斜率的最简整数比代入后求得的<span class="math">\(a = 2mn\)</span>总是偶数，这就是最后需要讨论<span class="math">\(m\)</span>和<span class="math">\(n\)</span>奇偶性的根本原因，任何互质的勾股数所对应的单位圆上的点，都存在和直线<span class="math">\(y = x\)</span>对称的另一点，其中一个点<span class="math">\(a\)</span>奇<span class="math">\(b\)</span>偶，对应<span class="math">\(m\)</span>和<span class="math">\(n\)</span>均为奇数的情况，另一个点<span class="math">\(a\)</span>偶<span class="math">\(b\)</span>奇，对应于<span class="math">\(m\)</span>和<span class="math">\(n\)</span>一奇一偶的情况。</p>
<p>解答完<a class="reference external" href="https://projecteuler.net/problem=9">第9个题目</a>即可在该题的说明中看到上述证明的具体过程。</p>
<p>（完）</p>
</div>
<script type='text/javascript'>if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width < 768) ? "left" : align;
        indent = (screen.width < 768) ? "0em" : indent;
        linebreak = (screen.width < 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
</script>
    </div>
<nav class="nav sidebar">
    <div class="siteinfo">
        <div class="sitename"><a href="../..">coinfaces</a></div>
        <div class="tagline">Another Side of Life</div>
    </div>

        <a href="../../categories/">categories</a>
        <a href="../..">&larr; Home</a>
</nav><footer class="footer">
    <span>
        &copy; jpli &middot;
        under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA 4.0</a>
    </span>
    |
    <span>
        Powered by:
        <a href="http://blog.getpelican.com/">Pelican</a>
    </span>
</footer></body>
</html>